package main

import scala.io.Source
import scala.util.matching.Regex
import uage.compiler.Tokenizer
import uage.compiler.Parser
import uage.ast._
import scala.collection.mutable.ListBuffer
import scala.util.control.Breaks
import scala.util.control.BreakControl
import uage.exception.ExprNotFoundException
import scala.collection.mutable.MapBuilder
import scala.collection.mutable.Queue
import java.util.ArrayList
import java.lang.invoke.MethodHandle
import java.lang.invoke.MethodType
import java.lang.invoke.MethodHandles.Lookup
import java.lang.invoke.MethodHandles

class parent{
  var name = "parent"
  var ch = new child()
  class child {
    var name2 = "child"
    name = "child changed"
  }
}

object Compiler {
  def main(args:Array[String]) = {
    val fileName = args(0)
    val file = Source.fromFile(fileName)
    
    val charIter = file.iter
    val tokenizer = new Tokenizer(charIter)
    val parser = new Parser(tokenizer)
    parser.parse()
//    parser.start()
    var arr:Array[Class[_]] = Array()
    var me = classOf[String].getMethod("length",arr:_*)
    
    var mt = MethodType.methodType(classOf[Int])
    var lookup = MethodHandles.lookup()
    var mh = lookup.findVirtual(classOf[String], "length", mt)
    println(mh.invoke("jjjj"))
    var al = new ArrayList[Object]()
    
    var clazz = Class.forName("java.util.ArrayList")
    var obj = clazz.newInstance()
    clazz.getMethods.foreach(m =>{
      if(m.getName == "add") println(m)
        
    })
    var method = clazz.getMethod("add", classOf[Object])
    method.invoke(obj, "elem1")
    method.invoke(obj, "elem2")
    println(obj)
  }
}